package org.styx.seata.tcc.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * Tcc接口
 * @date 2021/10/8
 * @auther uranus
 */
@LocalTCC
public interface OrderTccAction {
    /**
     * 第一阶段方法
     * @param businessActionContext
     * @param orderId
     * @param userId
     * @param productId
     * @param count
     * @param money
     * @return
     */
    @TwoPhaseBusinessAction(name = "orderTccAction",commitMethod = "commit",
            rollbackMethod = "rollback")
    boolean prepareCreateOrder(BusinessActionContext businessActionContext,
                               @BusinessActionContextParameter(paramName =
                                       "id") Long id,
                               @BusinessActionContextParameter(paramName =
                                       "userId") Long userId,
                               @BusinessActionContextParameter(paramName =
                                       "productdId") Long productId,
                               @BusinessActionContextParameter(paramName =
                                       "count") Integer count,
                               @BusinessActionContextParameter(paramName =
                                       "money") BigDecimal money);

    /**
     * 第二阶段提交
     * @param context
     * @return
     */
    boolean commit(BusinessActionContext context);

    /**
     * 第二阶段回滚
     * @param context
     * @return
     */
    boolean rollback(BusinessActionContext context);

}
